#define _CRT_SECURE_NO_WARNINGS 1


#include<vector>
#include<iostream>

using namespace std;

int maximumLength(vector<int>& nums, int k)
{
    int ans = 0;
    vector<vector<int>> f(k, vector<int>(k));
    for (int x : nums) 
    {
        x %= k;
        for (int y = 0; y < k; y++) 
        {
            f[y][x] = f[x][y] + 1;
            ans = max(ans, f[y][x]);
        }
    }
    return ans;
}

//int main()
//{
//    vector<int> v = { 1,4,2,3,1,4 };
//    cout << maximumLength(v, 3) << endl;
//
//    return 0;
//}